package hibernate.billStream;

import hibernate.p.Pair;
import java.util.*;

public class Service implements Commodity{
	
	private String name;
	private String note;
	private boolean isDefault;
	private Pair pricePerUnit=new Pair();
	
	private static TreeMap<String,Service> pool=new TreeMap<String,Service>();
	
	private Service(String n){
		name=n;
	}
	
	public static void createNew(String name,String note,boolean b,Pair p){
		Service ser=new Service(name);
		ser.setIsDefault(b);
		ser.setNote(note);
		ser.setPricePerUnit(p);
		pool.put(name+"|"+
				 note+"|"+
				 b+"|"+
				 p.getFirst().toString()+
				 "|"+p.getSecond().toString(), ser);
	}
	
	public static Service getService(String name){
		return pool.get(name);
	}
	
	public void setName(String name){
		this.name=name;
	}
	
	public String getName(){
		return name;
	}
	
	public void setNote(String note){
		this.note=note;
	}
	
	public String getNote(){
		return note;
	}
	
	public void setIsDefault(boolean ifIsDefault){
		isDefault=ifIsDefault;
	}
	
	public boolean getIsDefault(){
		return isDefault;
	}
	
	public void setPricePerUnit(Pair price){
		pricePerUnit=price;
	}
	
	public Pair getPricePerUnit(){
		return pricePerUnit;
	}
	
	public Pair getUnitPrice() {
		// TODO Auto-generated method stub
		return pricePerUnit;
	}
	
	public String toString(){
		return this.name+
			   "|"+this.note+
			   "|"+this.isDefault+
			   "|"+this.pricePerUnit.getFirst().toString()+
			   "|"+this.pricePerUnit.getSecond().toString();
	}
	
	//for debug only
	public static Service getRandomService(){
		int size=Service.pool.size();
		Random rnd=new Random();
		String name=Service.pool.keySet().toArray()[rnd.nextInt(size)].toString();
		return Service.pool.get(name);
	}
}
